package com.seeyon.apps.lzmzj.manager.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.lzmzj.kit.*;
import com.seeyon.apps.lzmzj.manager.MatrimonyFunctionManager;
import com.seeyon.cap4.form.bean.FormBean;
import com.seeyon.cap4.form.bean.FormDataMasterBean;
import com.seeyon.cap4.form.bean.FormDataSubBean;
import com.seeyon.cap4.form.bean.FormFieldBean;
import com.seeyon.cap4.form.service.CAP4FormManager;
import com.seeyon.cap4.template.manager.CAPDataListSqlHelpManager;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.ctpenumnew.manager.EnumManager;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.filemanager.manager.AttachmentManager;
import com.seeyon.ctp.common.filemanager.manager.FileManager;
import com.seeyon.ctp.common.log.CtpLogFactory;
import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumItem;
import com.seeyon.ctp.common.po.filemanager.V3XFile;
import com.seeyon.ctp.organization.bo.V3xOrgMember;
import com.seeyon.ctp.organization.manager.OrgManager;
import org.apache.commons.logging.Log;

import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

public class MatrimonyFunctionManagerImpl implements MatrimonyFunctionManager {

    private static final Log log = CtpLogFactory.getLog(MatrimonyFunctionManagerImpl.class);
    private static final String userName = AppContext.getSystemProperty("oa.userName");
    private static final String password = AppContext.getSystemProperty("oa.password");
    /*婚姻预约日历模版编码*/
    private String hyyyrl_unFlowformCode = AppContext.getSystemProperty("oaFormCode.hyyyrl_unFlowformCode");
    /*结婚登记档案*/
    private String jhdj_unFlowformCode = AppContext.getSystemProperty("oaFormCode.jhdj_unFlowformCode");
    /*离婚登记档案*/
    private String lhdj_unFlowformCode = AppContext.getSystemProperty("oaFormCode.lhdj_unFlowformCode");
    /*婚前辅导预约人合计*/
    private String hqfdyy_unFlowformCode = AppContext.getSystemProperty("oaFormCode.hqfdyy_unFlowformCode");
    /*陈规陋习曝光档案*/
    private String cglxbg_unFlowformCode = AppContext.getSystemProperty("oaFormCode.cglxbg_unFlowformCode");
    /*婚恋联谊活动档案*/
    private String hllyhd_unFlowformCode = AppContext.getSystemProperty("oaFormCode.hllyhd_unFlowformCode");
    /*婚姻登记证补领补办档案*/
    private String hydjzblbb_unFlowformCode = AppContext.getSystemProperty("oaFormCode.hydjzblbb_unFlowformCode");
    /*社会组织管理档案*/
    private String shzzgl_unFlowformCode = AppContext.getSystemProperty("oaFormCode.shzzgl_unFlowformCode");
    /*文明婚俗新风档案*/
    private String wmhsxf_unFlowformCode = AppContext.getSystemProperty("oaFormCode.wmhsxf_unFlowformCode");
    /*活动发布档案*/
    private String hdfb_unFlowformCode = AppContext.getSystemProperty("oaFormCode.hdfb_unFlowformCode");
    /*政策档案*/
    private String zc_unFlowformCode = AppContext.getSystemProperty("oaFormCode.zc_unFlowformCode");
    /*其他设置档案*/
    private String qtsz_unFlowformCode = AppContext.getSystemProperty("oaFormCode.qtsz_unFlowformCode");
    /*领导颁证档案*/
    private String ldbz_unFlowformCode = AppContext.getSystemProperty("oaFormCode.ldbz_unFlowformCode");
    /*泸州市收养儿童登记档案*/
    private String syetdj_unFlowformCode = AppContext.getSystemProperty("oaFormCode.syetdj_unFlowformCode");
    /*慈善资助申请(高中生)档案*/
    private String zszzsqg_unFlowformCode = AppContext.getSystemProperty("oaFormCode.zszzsqg_unFlowformCode");
    /*慈善资助申请(大学生)档案*/
    private String zszzsqd_unFlowformCode = AppContext.getSystemProperty("oaFormCode.zszzsqd_unFlowformCode");
    /*婚前辅导档案*/
    private String hqfd_unFlowformCode = AppContext.getSystemProperty("oaFormCode.hqfd_unFlowformCode");
    /*婚姻调解档案*/
    private String hytj_unFlowformCode = AppContext.getSystemProperty("oaFormCode.hytj_unFlowformCode");

    private OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager");
    private FileManager fileManager = (FileManager) AppContext.getBean("fileManager");
    private AttachmentManager attachmentManager = (AttachmentManager) AppContext.getBean("attachmentManager");
    private CAP4FormManager cap4FormManager = (CAP4FormManager) AppContext.getBean("cap4FormManager");
    private EnumManager enumManager = (EnumManager) AppContext.getBean("enumManagerNew");
    private CAPDataListSqlHelpManager capDataListSqlHelpManager = (CAPDataListSqlHelpManager) AppContext.getBean("capDataListSqlHelpManager");

    /**
     * 根据婚姻预约类型和区县等参数，获取婚姻预约日期列表
     *
     * @param param 参数映射，包含类型（type）、区域（region）、年份（year）和月份（month）
     * @return 包含婚姻预约日期及相关信息的映射表
     * @throws Exception 当婚姻预约类型编码或区县编码在OA系统中未找到对应枚举时抛出业务异常
     */
    @Override
    public Map<String, Object> getMatrimonyAppointmentDateList(Map<String, Object> param) throws Exception {
        // 初始化结果映射表
        Map<String, Object> result_dataMap = new HashMap<String, Object>();

        // 获取并转换婚姻预约类型编码
        String hyyylxCode = StrKit.str(param.get("type"));
        CtpEnumItem hyyylx_enumItem = DataConversionKit.getEnumByCode(hyyylxCode);
        // 检查婚姻预约类型编码是否有效
        if (hyyylx_enumItem == null) {
            throw new BusinessException("婚姻预约类型编码[" + hyyylxCode + "]在OA系统中未匹配到对应枚举");
        }

        // 获取并转换区县编码
        String qxCode = StrKit.str(param.get("region"));
        CtpEnumItem qx_enumItem = DataConversionKit.getEnumByCode(qxCode);
        // 检查区县编码是否有效
        if (qx_enumItem == null) {
            throw new BusinessException("区县编码[" + qxCode + "]在OA系统中未匹配到对应枚举");
        }

        // 根据表单代码获取婚姻预约日历表单信息
        FormBean hyyyrl_formBean = cap4FormManager.getFormByFormCode(hyyyrl_unFlowformCode);
        // 获取主表名
        String mainTableName = hyyyrl_formBean.getMasterTableBean().getTableName();

        // 获取字段名
        String hyyylx_fieldName = hyyyrl_formBean.getFieldBeanByDisplay("婚姻预约类型").getName();
        String qx_fieldName = hyyyrl_formBean.getFieldBeanByDisplay("区县").getName();
        String year_fieldName = hyyyrl_formBean.getFieldBeanByDisplay("年").getName();
        String month_fieldName = hyyyrl_formBean.getFieldBeanByDisplay("月").getName();
        String hs_fieldName = hyyyrl_formBean.getFieldBeanByDisplay("号数").getName();
        String subTableName = hyyyrl_formBean.getFieldBeanByDisplay("号数").getOwnerTableName();
        String yykssj_fieldName = hyyyrl_formBean.getFieldBeanByDisplay("预约开始时间").getName();
        String yyjssj_fieldName = hyyyrl_formBean.getFieldBeanByDisplay("预约结束时间").getName();
        String ryyyxz_fieldName = hyyyrl_formBean.getFieldBeanByDisplay("人员预约限制").getName();
        String yyyrs_fieldName = hyyyrl_formBean.getFieldBeanByDisplay("已预约人数").getName();
        String syyyrs_fieldName = hyyyrl_formBean.getFieldBeanByDisplay("剩余预约人数").getName();

        // 构建SQL查询语句
        StringBuilder stb = new StringBuilder();
        stb.append("SELECT f1.id,f1.").append(hs_fieldName).append(",f1.").append(yykssj_fieldName).append(",f1.");
        stb.append(yyjssj_fieldName).append(",f1.").append(ryyyxz_fieldName).append(",f1.").append(yyyrs_fieldName);
        stb.append(",f1.").append(syyyrs_fieldName).append(" FROM ").append(mainTableName).append(" f LEFT JOIN ");
        stb.append(subTableName).append(" f1 ON f.ID = f1.FORMMAIN_ID WHERE f.").append(hyyylx_fieldName).append(" = '");
        stb.append(hyyylx_enumItem.getId()).append("' AND f.").append(qx_fieldName).append(" = '").append(qx_enumItem.getId()).append("'");
        stb.append(" AND f.").append(year_fieldName).append(" = ").append(StrKit.toInteger(param.get("year")));
        stb.append(" AND f.").append(month_fieldName).append(" = ").append(StrKit.toInteger(param.get("month")));

        // 记录SQL查询语句日志
        log.info("根据婚姻预约类型区县年月维度,查询婚姻预约日历档案表数据信息sql语句:" + stb.toString());

        // 执行SQL查询并获取结果列表
        List<Object> list = capDataListSqlHelpManager.selectDataList(stb.toString(), null);

        // 处理查询结果
        if (!list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = (Map<String, Object>) list.get(i);
                String hs = StrKit.str(map.get(hs_fieldName));
                if (!"".equals(hs)) {
                    hs = enumManager.getCtpEnumItem(Long.parseLong(hs)).getShowvalue();
                }
                Map<String, Object> dataMap = new HashMap<String, Object>();

                String yykssj = StrKit.str(map.get(yykssj_fieldName));
                if (!"".equals(yykssj)) {
                    yykssj = DateKit.getDate4Cal((Date) map.get(yykssj_fieldName));
                }

                String yyjssj = StrKit.str(map.get(yyjssj_fieldName));
                if (!"".equals(yyjssj)) {
                    yyjssj = DateKit.getDate4Cal((Date) map.get(yyjssj_fieldName));
                }

                dataMap.put("id", StrKit.str(map.get("id")));
                dataMap.put("yyqzTime", yykssj + "-" + yyjssj);
                dataMap.put("limitNumber", StrKit.str(map.get(ryyyxz_fieldName)));
                dataMap.put("reservedNumber", StrKit.str(map.get(yyyrs_fieldName)));
                dataMap.put("remainingNumber", StrKit.str(map.get(syyyrs_fieldName)));

                if (!result_dataMap.containsKey(hs)) {
                    List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
                    dataList.add(dataMap);
                    result_dataMap.put(hs, dataList);
                } else {
                    List<Map<String, Object>> old_dataList = (List<Map<String, Object>>) result_dataMap.get(hs);
                    old_dataList.add(dataMap);
                    result_dataMap.put(hs, old_dataList);
                }
            }
        }

        // 返回处理后的结果映射表
        return result_dataMap;
    }


    /**
     * 根据参数获取婚姻登记相关的审批状态
     *
     * @param param 参数映射，包含类型(type)和预约编号(reservationNumber)
     * @return 包含审批状态的响应对象
     * @throws Exception 如果查询过程中发生错误
     */
    @Override
    public Object getMarriageRegistrationApprovalStatus(Map<String, Object> param, String url) throws Exception {
        // 从参数中提取类型
        String type = StrKit.str(param.get("type"));
        String telmplateCode = "";
        String nameStr = "";
        if ("J".equals(type) || "Y".equals(type)) {
            telmplateCode = jhdj_unFlowformCode;
            if ("J".equals(type)) {
                nameStr = "结婚预约登记";
            } else {
                nameStr = "结婚登记资料预填";
            }
        } else if ("L".equals(type) || "LHZL".equals(type)) {
            telmplateCode = lhdj_unFlowformCode;
            if ("L".equals(type)) {
                nameStr = "离婚预约登记";
            } else {
                nameStr = "离婚登记资料预填";
            }
        } else if ("C".equals(type)) {
            telmplateCode = cglxbg_unFlowformCode;
            nameStr = "陈规陋习曝光";
        } else if ("H".equals(type)) {
            telmplateCode = hllyhd_unFlowformCode;
            nameStr = "婚恋联谊活动";
        } else if ("B".equals(type)) {
            telmplateCode = hydjzblbb_unFlowformCode;
            nameStr = "婚姻登记证补领补办";
        } else if ("D".equals(type)) {
            telmplateCode = ldbz_unFlowformCode;
            nameStr = "领导颁证预约";
        } else if ("T".equals(type)) {
            telmplateCode = syetdj_unFlowformCode;
            nameStr = "收养儿童登记";
        } else if ("ZG".equals(type)) {
            telmplateCode = zszzsqg_unFlowformCode;
            nameStr = "慈善资助申请(高中生)";
        } else if ("ZD".equals(type)) {
            telmplateCode = zszzsqd_unFlowformCode;
            nameStr = "慈善资助申请(大学生)";
        } else if ("Q".equals(type)) {
            telmplateCode = hqfd_unFlowformCode;
            nameStr = "婚前辅导预约";
        } else if ("TJ".equals(type)) {
            telmplateCode = hytj_unFlowformCode;
            nameStr = "婚姻调解预约";
        }
        // 根据模板代码获取表单信息
        FormBean formBean = cap4FormManager.getFormByFormCode(telmplateCode);
        // 获取主表名
        String yyrsfzh_fieldName = formBean.getFieldBeanByDisplay("预约人身份证号").getName();
        String mainTableName = formBean.getFieldBeanByDisplay("预约人身份证号").getOwnerTableName();
        List<Object> list = new ArrayList<Object>();
        List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
        String reservationNumber = StrKit.str(param.get("reservationNumber"));
        if ("D".equals(type)) {
            String yyrq_fieldName = formBean.getFieldBeanByDisplay("预约日期").getName();
            String yyrxm_fieldName = formBean.getFieldBeanByDisplay("预约人姓名").getName();
            String lxdh_fieldName = formBean.getFieldBeanByDisplay("联系电话").getName();
            String yybzjg_fieldName = formBean.getFieldBeanByDisplay("预约颁证机关").getName();
            StringBuilder stb_ldbz = new StringBuilder();
            stb_ldbz.append("SELECT id,formmain_id,").append(yyrq_fieldName).append(",").append(yyrxm_fieldName).append(",");
            stb_ldbz.append(lxdh_fieldName).append(",").append(yybzjg_fieldName).append(" from ").append(mainTableName).append(" WHERE ");
            stb_ldbz.append(yyrsfzh_fieldName).append(" = '").append(reservationNumber).append("'");
            log.info("根据预约人身份证号查询[" + nameStr + "]数据信息sql语句:" + stb_ldbz.toString());
            list = capDataListSqlHelpManager.selectDataList(stb_ldbz.toString(), null);
            if (list.isEmpty()) {
                // 如果没有查询结果，返回错误消息
                return MessageKit.msg("E", "data", "", "根据身份证号[" + reservationNumber + "]未查询到[" + nameStr + "]信息");
            } else {
                for (int j = 0; j < list.size(); j++) {
                    Map<String, Object> map_ldbz = new HashMap<String, Object>();
                    Map<String, Object> row_ldbz = (Map<String, Object>) list.get(j);
                    map_ldbz.put("id", StrKit.str(row_ldbz.get("id")));
                    Object yyrq = row_ldbz.get(yyrq_fieldName);
                    String reservationDate = "";
                    if (!"".equals(StrKit.str(yyrq))) {
                        reservationDate = new SimpleDateFormat("yyyy-MM-dd").format((Date) yyrq);
                    }
                    map_ldbz.put("reservationName", StrKit.str(row_ldbz.get(yyrxm_fieldName)));
                    map_ldbz.put("reservationDate", reservationDate);
                    map_ldbz.put("reservationPhone", StrKit.str(row_ldbz.get(lxdh_fieldName)));
                    String yybzjg = StrKit.str(row_ldbz.get(yybzjg_fieldName));
                    String reservationAuthority = "";
                    if (!"".equals(yybzjg)) {
                        reservationAuthority = enumManager.getCtpEnumItem(Long.parseLong(yybzjg)).getShowvalue();
                    }
                    map_ldbz.put("reservationAuthority", reservationAuthority);
                    dataList.add(map_ldbz);
                }
            }
            return MessageKit.msg("S", "data", dataList, "");
        } else {
            StringBuilder stb = new StringBuilder();
            stb.append("SELECT id from ").append(mainTableName).append(" WHERE ");
            stb.append(yyrsfzh_fieldName).append(" = '").append(StrKit.str(param.get("reservationNumber"))).append("'");
            log.info("根据预约人身份证号查询[" + nameStr + "]数据信息sql语句:" + stb.toString());
            list = capDataListSqlHelpManager.selectDataList(stb.toString(), null);
        }
        if (list.isEmpty()) {
            // 如果没有查询结果，返回错误消息
            return MessageKit.msg("E", "data", "", "根据身份证号[" + reservationNumber + "]未查询到[" + nameStr + "]信息");
        }
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            Map<String, Object> map = (Map<String, Object>) list.get(i);
            String dataId = StrKit.str(map.get("id"));
            FormDataMasterBean formDataMasterBean = cap4FormManager.getDataMasterBeanById(Long.parseLong(dataId), formBean, null);
            dataMap.put("id", dataId);
            List<FormFieldBean> formFieldBeans = formDataMasterBean.getFormTable().getFields();
            for (FormFieldBean formFieldBean : formFieldBeans) {
                String desc = formFieldBean.getDesc().trim();
                if (!"".equals(desc)) {
                    if (desc.contains("J_") || desc.contains("jy_") || desc.contains("Y_")) {
                        String mapKey = "";
                        if ("J".equals(type)) {
                            if (desc.contains("jy_")) {
                                mapKey = desc.split("jy_")[1];
                            } else if (desc.contains("J_")) {
                                mapKey = desc.split("J_")[1];
                            }
                        } else if ("Y".equals(type)) {
                            if (desc.contains("jy_")) {
                                mapKey = desc.split("jy_")[1];
                            } else if (desc.contains("Y_")) {
                                mapKey = desc.split("Y_")[1];
                            }
                        }
                        if (!"".equals(mapKey)) {
                            Object fieldValue = formDataMasterBean.getFieldValue(formFieldBean.getName());
                            String fieldValue_new = StrKit.str(fieldValue);
                            if (!"".equals(fieldValue_new)) {
                                String fieldType = formFieldBean.getInputType();
                                dataMap.put(mapKey, getData(fieldType, fieldValue, url));
                            } else {
                                dataMap.put(mapKey, fieldValue_new);
                            }
                        }
                    } else if (desc.contains("L_") || desc.contains("lh_") || desc.contains("lhzlyt_")) {
                        String mapKey = "";
                        if ("L".equals(type)) {
                            if (desc.contains("lh_")) {
                                mapKey = desc.split("lh_")[1];
                            } else if (desc.contains("L_")) {
                                mapKey = desc.split("L_")[1];
                            }
                        } else if ("LHZL".equals(type)) {
                            if (desc.contains("lh_")) {
                                mapKey = desc.split("lh_")[1];
                            } else if (desc.contains("lhzlyt_")) {
                                mapKey = desc.split("lhzlyt_")[1];
                            }
                        }
                        if (!"".equals(mapKey)) {
                            Object fieldValue = formDataMasterBean.getFieldValue(formFieldBean.getName());
                            String fieldValue_new = StrKit.str(fieldValue);
                            if (!"".equals(fieldValue_new)) {
                                String fieldType = formFieldBean.getInputType();
                                dataMap.put(mapKey, getData(fieldType, fieldValue, url));
                            } else {
                                dataMap.put(mapKey, fieldValue_new);
                            }
                        }
                    } else {
                        String mapKey = desc;
                        Object fieldValue = formDataMasterBean.getFieldValue(formFieldBean.getName());
                        String fieldValue_new = StrKit.str(fieldValue);
                        if (!"".equals(fieldValue_new)) {
                            String fieldType = formFieldBean.getInputType();
                            dataMap.put(mapKey, getData(fieldType, fieldValue, url));
                        } else {
                            dataMap.put(mapKey, fieldValue_new);
                        }
                    }
                }
            }
            if (dataMap.containsKey("占进程用")) {
                dataMap.remove("占进程用");
            }
            dataList.add(dataMap);
        }

        // 返回包含审批状态的响应对象
        return MessageKit.msg("S", "data", dataList, "");
    }

    /**
     * 根据参数获取婚前辅导预约信息
     * 该方法通过查询数据库，根据年份、月份和地区参数获取婚前辅导的预约限制人数和可用名额
     * 主要步骤包括：获取表单信息、构造SQL查询、执行查询、处理查询结果并返回相应信息
     *
     * @param param 查询参数，包括年份、月份和地区等信息
     * @return 包含预约限制人数和可用名额的Map，或者错误消息
     * @throws Exception 如果查询过程中发生错误或参数无效则抛出异常
     */
    @Override
    public Object getPremaritalCounselingAppointmentNumber(Map<String, Object> param) throws Exception {
        // 通过表单代码获取表单对象
        FormBean formBean = cap4FormManager.getFormByFormCode(hqfdyy_unFlowformCode);
        // 获取主表名
        String mainTableName = formBean.getMasterTableBean().getTableName();
        // 获取年份字段名
        String year_fieldName = formBean.getFieldBeanByDisplay("年").getName();
        // 获取月份字段名
        String month_fieldName = formBean.getFieldBeanByDisplay("月").getName();
        // 获取地区字段名
        String dq_fieldName = formBean.getFieldBeanByDisplay("地区").getName();
        // 获取预约限制人数字段名
        String yyxzrs_fieldName = formBean.getFieldBeanByDisplay("预约限制人数").getName();
        // 获取子表名
        String subTableName = formBean.getFieldBeanByDisplay("身份证号").getOwnerTableName();
        // 构造SQL查询字符串
        StringBuilder stb = new StringBuilder();
        stb.append("SELECT id,").append(yyxzrs_fieldName).append(" FROM ").append(mainTableName);
        // 添加年份条件
        String year = StrKit.str(param.get("year"));
        stb.append(" WHERE ").append(year_fieldName).append(" = '").append(year).append("'");
        // 添加月份条件
        String month = StrKit.str(param.get("month"));
        stb.append(" AND ").append(month_fieldName).append(" = '").append(month).append("'");
        // 添加地区条件
        String region = StrKit.str(param.get("region"));
        CtpEnumItem ctpEnumItem = DataConversionKit.getEnumByCode(region);
        if (ctpEnumItem == null) {
            throw new BusinessException(" 地区编码[" + region + "]在系统中未匹配到对应地区值");
        } else {
            stb.append(" AND ").append(dq_fieldName).append(" = '").append(ctpEnumItem.getId()).append("'");
        }
        // 打印SQL查询语句
        log.info("根据年月地区查询婚前辅导预约人数sql语句:" + stb.toString());
        // 执行SQL查询
        List<Object> list = capDataListSqlHelpManager.selectDataList(stb.toString(), null);
        // 处理查询结果
        if (list.isEmpty()) {
            return MessageKit.msg("E", "data", "", "根据年[" + year + "]、月[" + month + "]、地址[" + region + "]在系统中未查询到对应的数据信息!");
        } else {
            // 获取查询结果的第一条记录
            Map<String, Object> map = (Map<String, Object>) list.get(0);
            // 获取预约限制人数
            int yyxzrs = StrKit.toInteger(map.get(yyxzrs_fieldName));
            // 获取数据ID
            String dataId = StrKit.str(map.get("id"));
            // 根据ID获取主表数据对象
            FormDataMasterBean formDataMasterBean = cap4FormManager.getDataMasterBeanById(Long.parseLong(dataId), formBean, null);
            // 获取子表数据列表
            List<FormDataSubBean> formDataSubBeans = formDataMasterBean.getSubData(subTableName);
            // 统计已预约人数
            int num = 0;
            for (FormDataSubBean formDataSubBean : formDataSubBeans) {
                String sfzh = StrKit.str(formDataSubBean.getFieldValue(formBean.getFieldBeanByDisplay("身份证号").getName()));
                if (!"".equals(sfzh)) {
                    num = num + 1;
                }
            }
            // 计算可用名额
            int num_new = yyxzrs - num;
            // 构造返回数据
            Map<String, Object> dataMap = new HashMap<String, Object>();
            dataMap.put("restrictQuantity", yyxzrs);
            dataMap.put("availableQuantity", num_new);
            return MessageKit.msg("S", "data", dataMap, "");
        }
    }

    /**
     * 查询文明婚俗新风档案列表数据
     *
     * @param param 查询参数，可能包含地区和标题
     * @param url   文件的URL，用于获取附件和图片的完整路径
     * @return 包含数据列表的集合
     * @throws Exception 根据业务需求可能抛出的异常
     */
    @Override
    public Object queryCivilizationMarriageCustomNewTrend(Map<String, Object> param, String url) throws Exception {
        // 初始化数据列表
        List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();

        // 通过表单代码获取表单对象
        FormBean formBean = cap4FormManager.getFormByFormCode(wmhsxf_unFlowformCode);

        // 获取主表名
        String mainTableName = formBean.getMasterTableBean().getTableName();

        // 获取各字段名
        String bt_fieldName = formBean.getFieldBeanByDisplay("标题").getName();
        String fgsj_fieldName = formBean.getFieldBeanByDisplay("发稿时间").getName();
        String dq_fieldName = formBean.getFieldBeanByDisplay("地区").getName();
        String zw_fieldName = formBean.getFieldBeanByDisplay("正文").getName();
        String zwtp_fieldName = formBean.getFieldBeanByDisplay("正文图片").getName();
        String zwfj_fieldName = formBean.getFieldBeanByDisplay("正文附件").getName();
        String qfr_fieldName = formBean.getFieldBeanByDisplay("签发人").getName();
        String ngr_fieldName = formBean.getFieldBeanByDisplay("拟稿人").getName();

        // 构建SQL查询语句
        StringBuilder stb = new StringBuilder();
        stb.append("SELECT id,").append(bt_fieldName).append(",").append(fgsj_fieldName);
        stb.append(",").append(dq_fieldName).append(",").append(zw_fieldName).append(",");
        stb.append(zwtp_fieldName).append(",").append(zwfj_fieldName).append(",");
        stb.append(qfr_fieldName).append(",").append(ngr_fieldName).append(" FROM ");
        stb.append(mainTableName).append(" WHERE 1=1 ");

        // 根据参数添加地区条件
        if (param.containsKey("region")) {
            String region = StrKit.str(param.get("region"));
            if (!"".equals(region)) {
                CtpEnumItem ctpEnumItem = DataConversionKit.getEnumByCode(region);
                stb.append(" AND ").append(dq_fieldName).append(" ='").append(ctpEnumItem.getId()).append("'");
            }
        }

        // 根据参数添加标题条件
        if (param.containsKey("title")) {
            String title = StrKit.str(param.get("title"));
            if (!"".equals(title)) {
                stb.append(" AND ").append(bt_fieldName).append(" LKIE '%").append(title).append("%'");
            }
        }

        // 记录SQL查询语句日志
        log.info("查询文明婚俗新风档案列表数据SQL语句:" + stb.toString());

        // 执行SQL查询并获取结果列表
        List<Object> list = capDataListSqlHelpManager.selectDataList(stb.toString(), null);

        // 遍历结果列表，封装数据
        if (!list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> dataMap = new HashMap<String, Object>();
                Map<String, Object> map = (Map<String, Object>) list.get(i);
                dataMap.put("id", StrKit.str(map.get("id")));
                // 封装标题和发布时间
                dataMap.put("title", StrKit.str(map.get(bt_fieldName)));
                Object fgsj = map.get(fgsj_fieldName);
                String pressTime = "";
                if (!"".equals(StrKit.str(fgsj))) {
                    pressTime = new SimpleDateFormat("yyyy-MM-dd").format((Date) fgsj);
                }
                dataMap.put("pressTime", pressTime);

                // 封装地区信息
                String dqId = StrKit.str(map.get(dq_fieldName));
                Map<String, Object> regionMap = new HashMap<String, Object>();
                if (!"".equals(dqId)) {
                    CtpEnumItem ctpEnumItem = enumManager.getCtpEnumItem(Long.parseLong(dqId));
                    regionMap.put("name", ctpEnumItem.getShowvalue());
                    regionMap.put("code", ctpEnumItem.getEnumItemCode());
                }
                dataMap.put("region", regionMap);

                // 封装正文内容
                dataMap.put("content", StrKit.str(map.get(zw_fieldName)));

                // 封装正文图片列表
                String zwtp = StrKit.str(map.get(zwtp_fieldName));
                List<Map<String, Object>> imageList = new ArrayList<Map<String, Object>>();
                if (!"".equals(zwtp)) {
                    imageList = getFile(zwtp, url);
                }
                dataMap.put("image", imageList);

                // 封装正文附件列表
                String zwfj = StrKit.str(map.get(zwfj_fieldName));
                List<Map<String, Object>> fileList = new ArrayList<Map<String, Object>>();
                if (!"".equals(zwfj)) {
                    fileList = getFile(zwfj, url);
                }
                dataMap.put("attachment", fileList);

                // 封装拟稿人和签发人信息
                String ngrId = StrKit.str(map.get(ngr_fieldName));
                String ngrName = "";
                if (!"".equals(ngrId)) {
                    ngrName = orgManager.getMemberById(Long.parseLong(ngrId)).getName();
                }
                dataMap.put("drafter", ngrName);

                String qfrId = StrKit.str(map.get(qfr_fieldName));
                String qfrName = "";
                if (!"".equals(qfrId)) {
                    qfrName = orgManager.getMemberById(Long.parseLong(qfrId)).getName();
                }
                dataMap.put("signer", qfrName);

                // 将封装好的数据添加到数据列表
                dataList.add(dataMap);
            }
        }

        // 返回数据列表
        return MessageKit.msg("S", "data", dataList, "");
    }


    /**
     * 查询活动发布档案列表数据
     *
     * @param param 查询参数，可能包含地区和活动名称
     * @param url   文件的URL，用于获取附件和图片的完整路径
     * @return 包含数据列表的集合
     * @throws Exception 根据业务需求可能抛出的异常
     */
    @Override
    public Object queryEventRelease(Map<String, Object> param, String url) throws Exception {
        // 初始化一个存储数据的列表
        List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
        // 通过表单代码获取表单对象
        FormBean formBean = cap4FormManager.getFormByFormCode(hdfb_unFlowformCode);
        // 获取主表的表名
        String mainTableName = formBean.getMasterTableBean().getTableName();
        // 通过显示名称获取字段名：活动名称
        String hdmc_fieldName = formBean.getFieldBeanByDisplay("活动名称").getName();
        // 通过显示名称获取字段名：活动开始日期
        String hdksrq_fieldName = formBean.getFieldBeanByDisplay("活动开始日期").getName();
        // 通过显示名称获取字段名：活动结束日期
        String hdjsrq_fieldName = formBean.getFieldBeanByDisplay("活动结束日期").getName();
        // 通过显示名称获取字段名：报名开始日期
        String bmksrq_fieldName = formBean.getFieldBeanByDisplay("报名开始日期").getName();
        // 通过显示名称获取字段名：报名结束日期
        String bmjsrq_fieldName = formBean.getFieldBeanByDisplay("报名结束日期").getName();
        // 通过显示名称获取字段名：联系人
        String lxr_fieldName = formBean.getFieldBeanByDisplay("联系人").getName();
        // 通过显示名称获取字段名：联系人电话
        String lxrdh_fieldName = formBean.getFieldBeanByDisplay("联系人电话").getName();
        // 通过显示名称获取字段名：发布日期
        String fbrq_fieldName = formBean.getFieldBeanByDisplay("发布日期").getName();
        // 通过显示名称获取字段名：地区
        String dq_fieldName = formBean.getFieldBeanByDisplay("地区").getName();
        // 通过显示名称获取字段名：活动类型
        String hdlx_fieldName = formBean.getFieldBeanByDisplay("活动类型").getName();
        // 通过显示名称获取字段名：活动地点
        String hddd_fieldName = formBean.getFieldBeanByDisplay("活动地点").getName();
        // 通过显示名称获取字段名：活动负责方
        String hdfzf_fieldName = formBean.getFieldBeanByDisplay("活动负责方").getName();
        // 通过显示名称获取字段名：活动详情
        String hdxq_fieldName = formBean.getFieldBeanByDisplay("活动详情").getName();
        // 通过显示名称获取字段名：活动图片
        String hdtp_fieldName = formBean.getFieldBeanByDisplay("活动图片").getName();
        // 通过显示名称获取字段名：活动视频
        String hdsp_fieldName = formBean.getFieldBeanByDisplay("活动视频").getName();
        // 通过显示名称获取字段名：相关附件
        String xgfj_fieldName = formBean.getFieldBeanByDisplay("相关附件").getName();
        // 构建SQL查询语句
        StringBuilder stb = new StringBuilder();
        stb.append("select id,").append(hdmc_fieldName).append(",").append(hdksrq_fieldName).append(",").append(hdjsrq_fieldName).append(",").append(bmksrq_fieldName).append(",");
        stb.append(bmjsrq_fieldName).append(",").append(lxr_fieldName).append(",").append(lxrdh_fieldName).append(",").append(fbrq_fieldName).append(",").append(dq_fieldName).append(",");
        stb.append(hdlx_fieldName).append(",").append(hddd_fieldName).append(",").append(hdfzf_fieldName).append(",").append(hdxq_fieldName).append(",").append(hdtp_fieldName).append(",");
        stb.append(hdsp_fieldName).append(",").append(xgfj_fieldName).append(" from ").append(mainTableName).append(" where 1=1 ");
        // 根据地区参数添加SQL查询条件
        if (param.containsKey("region")) {
            String region = StrKit.str(param.get("region"));
            if (!"".equals(region)) {
                CtpEnumItem ctpEnumItem = DataConversionKit.getEnumByCode(region);
                stb.append(" AND ").append(dq_fieldName).append(" ='").append(ctpEnumItem.getId()).append("'");
            }
        }
        // 根据活动名称参数添加SQL查询条件
        if (param.containsKey("activityName")) {
            String activityName = StrKit.str(param.get("activityName"));
            if (!"".equals(activityName)) {
                stb.append(" AND ").append(hdmc_fieldName).append(" LKIE '%").append(activityName).append("%'");
            }
        }
        // 记录SQL查询语句日志
        log.info("查询活动发布档案列表数据SQL语句:" + stb.toString());
        // 执行SQL查询语句，获取数据列表
        List<Object> list = capDataListSqlHelpManager.selectDataList(stb.toString(), null);
        // 如果列表不为空，处理列表中的每一项
        if (!list.isEmpty()) {
            // 遍历列表中的每个元素
            for (int i = 0; i < list.size(); i++) {
                // 将当前元素转换为Map类型
                Map<String, Object> map = (Map<String, Object>) list.get(i);
                // 创建一个新的Map用于存储处理后的数据
                Map<String, Object> dataMap = new HashMap<String, Object>();

                // 从map中获取"id"，并转换为字符串后存入dataMap
                dataMap.put("id", StrKit.str(map.get("id")));
                // 从map中获取活动名称，并存入dataMap
                dataMap.put("activityName", StrKit.str(map.get(hdmc_fieldName)));

                // 获取活动开始日期，如果存在则格式化后存入dataMap
                Object hdksrq = map.get(hdksrq_fieldName);
                String activity_startDate = "";
                if (!"".equals(StrKit.str(hdksrq))) {
                    activity_startDate = new SimpleDateFormat("yyyy-MM-dd").format((Date) hdksrq);
                }
                dataMap.put("activity_startDate", activity_startDate);

                // 获取活动结束日期，如果存在则格式化后存入dataMap
                Object hdjsrq = map.get(hdjsrq_fieldName);
                String activity_endDate = "";
                if (!"".equals(StrKit.str(hdjsrq))) {
                    activity_endDate = new SimpleDateFormat("yyyy-MM-dd").format((Date) hdjsrq);
                }
                dataMap.put("activity_endDate", activity_endDate);

                // 获取报名开始日期，如果存在则格式化后存入dataMap
                Object bmksrq = map.get(bmksrq_fieldName);
                String signup_startDate = "";
                if (!"".equals(StrKit.str(bmksrq))) {
                    signup_startDate = new SimpleDateFormat("yyyy-MM-dd").format((Date) bmksrq);
                }
                dataMap.put("signup_startDate", signup_startDate);

                // 获取报名结束日期，如果存在则格式化后存入dataMap
                Object bmjsrq = map.get(bmjsrq_fieldName);
                String signup_endDate = "";
                if (!"".equals(StrKit.str(bmjsrq))) {
                    signup_endDate = new SimpleDateFormat("yyyy-MM-dd").format((Date) bmjsrq);
                }
                dataMap.put("signup_endDate", signup_endDate);

                // 从map中获取联系人，并存入dataMap
                dataMap.put("contact", StrKit.str(map.get(lxr_fieldName)));
                // 从map中获取联系人电话，并存入dataMap
                dataMap.put("contact_phone", StrKit.str(map.get(lxrdh_fieldName)));

                // 获取发布日期，如果存在则格式化后存入dataMap
                Object fbrq = map.get(fbrq_fieldName);
                String publish_date = "";
                if (!"".equals(StrKit.str(fbrq))) {
                    publish_date = new SimpleDateFormat("yyyy-MM-dd").format((Date) fbrq);
                }
                dataMap.put("publish_date", publish_date);

                // 获取地区ID，如果存在则获取对应的地区名称和代码存入dataMap
                String dqId = StrKit.str(map.get(dq_fieldName));
                Map<String, Object> regionMap = new HashMap<String, Object>();
                if (!"".equals(dqId)) {
                    CtpEnumItem ctpEnumItem = enumManager.getCtpEnumItem(Long.parseLong(dqId));
                    regionMap.put("name", ctpEnumItem.getShowvalue());
                    regionMap.put("code", ctpEnumItem.getEnumItemCode());
                }
                dataMap.put("region", regionMap);

                // 获取活动类型ID，如果存在则获取对应的活动类型名称存入dataMap
                String hdlxId = StrKit.str(map.get(hdlx_fieldName));
                String activity_type = "";
                if (!"".equals(hdlxId)) {
                    activity_type = enumManager.getCtpEnumItem(Long.parseLong(hdlxId)).getShowvalue();
                }
                dataMap.put("activity_type", activity_type);

                // 从map中获取活动地点，并存入dataMap
                dataMap.put("activity_place", StrKit.str(map.get(hddd_fieldName)));
                // 从map中获取活动详情，并存入dataMap
                dataMap.put("activity_detail", StrKit.str(map.get(hdxq_fieldName)));
                // 从map中获取活动负责人，并存入dataMap
                dataMap.put("activity_responsibleParty", StrKit.str(map.get(hdfzf_fieldName)));

                // 获取活动图片，如果存在则解析后存入dataMap
                String hdtp = StrKit.str(map.get(hdtp_fieldName));
                List<Map<String, Object>> imageList = new ArrayList<Map<String, Object>>();
                if (!"".equals(hdtp)) {
                    imageList = getFile(hdtp, url);
                }
                dataMap.put("activity_image", imageList);

                // 获取活动视频，如果存在则解析后存入dataMap
                String hdsp = StrKit.str(map.get(hdsp_fieldName));
                List<Map<String, Object>> videoList = new ArrayList<Map<String, Object>>();
                if (!"".equals(hdsp)) {
                    videoList = getFile(hdsp, url);
                }
                dataMap.put("activity_video", videoList);

                // 获取附件，如果存在则解析后存入dataMap
                String xgfj = StrKit.str(map.get(xgfj_fieldName));
                List<Map<String, Object>> fileList = new ArrayList<Map<String, Object>>();
                if (!"".equals(xgfj)) {
                    fileList = getFile(xgfj, url);
                }
                dataMap.put("related_accessory", fileList);

                // 将处理后的dataMap添加到dataList中
                dataList.add(dataMap);
            }
        }
        // 返回处理后的数据列表
        return MessageKit.msg("S", "data", dataList, "");

    }

    /**
     * 查询政策档案列表
     *
     * @param param 查询参数，可能包含政策名称等信息
     * @return 包含政策档案数据的MessageKit对象
     * @throws Exception 如果查询过程中发生错误，则抛出异常
     */
    @Override
    public Object queryPolicyArchives(Map<String, Object> param) throws Exception {
        // 初始化数据列表
        List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
        // 通过表单代码获取表单信息
        FormBean formBean = cap4FormManager.getFormByFormCode(zc_unFlowformCode);
        // 获取主表的表名
        String tableName = formBean.getMasterTableBean().getTableName();
        // 通过字段显示名称获取实际字段名
        String zcmc_fieldName = formBean.getFieldBeanByDisplay("政策名称").getName();
        String nrjj_fieldName = formBean.getFieldBeanByDisplay("内容简介").getName();
        String gzlc_fieldName = formBean.getFieldBeanByDisplay("工作流程").getName();
        String sxyq_fieldName = formBean.getFieldBeanByDisplay("时限要求").getName();
        String zcly_fieldName = formBean.getFieldBeanByDisplay("政策来源").getName();
        String zgdw_fieldName = formBean.getFieldBeanByDisplay("主管单位及咨询电话").getName();
        // 构建SQL查询语句
        StringBuilder stb = new StringBuilder();
        stb.append("select id,").append(zcmc_fieldName).append(",").append(nrjj_fieldName);
        stb.append(",").append(gzlc_fieldName).append(",").append(sxyq_fieldName).append(",");
        stb.append(zcly_fieldName).append(",").append(zgdw_fieldName).append(" from ");
        stb.append(tableName).append(" where 1=1 ");
        // 如果查询参数中包含政策名称，则添加到SQL中作为条件
        if (param.containsKey("policyName")) {
            String policyName = StrKit.str(param.get("policyName"));
            if (!"".equals(policyName)) {
                stb.append(" AND ").append(zcmc_fieldName).append(" LIKE '%").append(policyName).append("%'");
            }
        }
        // 记录SQL查询语句日志
        log.info("查询政策档案列表数据SQL语句:" + stb.toString());
        // 执行SQL查询并获取结果列表
        List<Map<String, Object>> list = capDataListSqlHelpManager.selectDataList(stb.toString(), null);
        // 遍历查询结果，封装成所需的数据格式
        if (!list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = (Map<String, Object>) list.get(i);
                Map<String, Object> dataMap = new HashMap<String, Object>();
                dataMap.put("policyName", StrKit.str(map.get(zcmc_fieldName)));
                dataMap.put("policyDetail", StrKit.str(map.get(nrjj_fieldName)));
                dataMap.put("workflow", StrKit.str(map.get(gzlc_fieldName)));
                dataMap.put("timeLimit", StrKit.str(map.get(sxyq_fieldName)));
                dataMap.put("policySource", StrKit.str(map.get(zcly_fieldName)));
                dataMap.put("competentUnit", StrKit.str(map.get(zgdw_fieldName)));
                dataList.add(dataMap);
            }
        }
        // 返回成功消息，携带查询到的数据列表
        return MessageKit.msg("S", "data", dataList, "");
    }

    /**
     * 查询其他通知设置
     * 根据不同的预约类型，查询相应的通知信息
     * 支持的类型包括：结婚登记(J)、离婚申请(L)、领导颁证(Y)、婚姻调节(T)
     *
     * @param param 包含类型信息的参数映射
     * @param url   文件服务的URL
     * @return 查询到的通知信息列表
     * @throws Exception 如果查询过程中发生错误
     */
    @Override
    public Object queryOtherNotice(Map<String, Object> param, String url) throws Exception {
        // 初始化数据列表
        List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();

        // 通过表单代码获取表单对象
        FormBean formBean = cap4FormManager.getFormByFormCode(qtsz_unFlowformCode);

        // 获取数据库表名
        String tableName = formBean.getMasterTableBean().getTableName();

        // 获取各个字段的名称
        String jhdj_xz_fieldName = formBean.getFieldBeanByDisplay("预约须知_结婚登记").getName();
        String jhdj_jhdjwsyyxy_fieldName = formBean.getFieldBeanByDisplay("结婚登记网上预约协议").getName();
        String ldbz_xz_fieldName = formBean.getFieldBeanByDisplay("预约须知_领导颁证").getName();
        String hytj_xz_fieldName = formBean.getFieldBeanByDisplay("预约须知_婚姻调节").getName();
        String jhdj_hyjyxcp_fieldName = formBean.getFieldBeanByDisplay("婚姻教育宣传片_结婚登记").getName();
        String lhsq_xz_fieldName = formBean.getFieldBeanByDisplay("预约须知_离婚申请").getName();

        // 构建SQL查询语句
        StringBuilder stb = new StringBuilder();
        stb.append("select id");
        String type = "";
        if (param.containsKey("type")) {
            type = StrKit.str(param.get("type"));
            if ("J".equals(type)) {
                // 结婚登记类型
                stb.append(",").append(jhdj_xz_fieldName).append(",").append(jhdj_hyjyxcp_fieldName);
                stb.append(",").append(jhdj_jhdjwsyyxy_fieldName);
            } else if ("L".equals(type)) {
                // 离婚申请类型
                stb.append(",").append(lhsq_xz_fieldName);
            } else if ("Y".equals(type)) {
                // 领导颁证类型
                stb.append(",").append(ldbz_xz_fieldName);
            } else if ("T".equals(type)) {
                // 婚姻调节类型
                stb.append(",").append(hytj_xz_fieldName);
            }
        }
        // 完成SQL语句构建
        stb.append(" from ").append(tableName);

        // 记录SQL查询语句
        log.info("查询其他设置档案列表数据SQL语句:" + stb.toString());

        // 执行SQL查询
        List<Map<String, Object>> list = capDataListSqlHelpManager.selectDataList(stb.toString(), null);

        // 处理查询结果
        if (!list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = (Map<String, Object>) list.get(i);
                Map<String, Object> dataMap = new HashMap<String, Object>();
                if ("J".equals(type)) {
                    // 处理结婚登记类型的查询结果
                    dataMap.put("notice", StrKit.str(map.get(jhdj_xz_fieldName)));
                    String video = StrKit.str(map.get(jhdj_hyjyxcp_fieldName));
                    List<Map<String, Object>> videoList = new ArrayList<Map<String, Object>>();
                    if (!"".equals(video)) {
                        videoList = getFile(video, url);
                    }
                    dataMap.put("video", videoList);
                    dataMap.put("protocol", StrKit.str(map.get(jhdj_jhdjwsyyxy_fieldName)));
                } else if ("L".equals(type)) {
                    // 处理离婚申请类型的查询结果
                    dataMap.put("notice", StrKit.str(map.get(lhsq_xz_fieldName)));
                } else if ("Y".equals(type)) {
                    // 处理领导颁证类型的查询结果
                    dataMap.put("notice", StrKit.str(map.get(ldbz_xz_fieldName)));
                } else if ("T".equals(type)) {
                    // 处理婚姻调节类型的查询结果
                    dataMap.put("notice", StrKit.str(map.get(hytj_xz_fieldName)));
                }
                dataList.add(dataMap);
            }
        }

        // 返回查询到的通知信息列表
        return MessageKit.msg("S", "data", dataList, "");
    }

    /**
     * 根据模板编码和表单数据获取组织成员信息
     *
     * @param templateCode 模板编码，用于查询特定的表单数据
     * @param mainData     表单的主要数据，包含用户输入的各种字段
     * @param formBean     表单对象，包含了表单的结构和字段定义
     * @return 返回一个V3xOrgMember对象，该对象包含了经办人的组织成员信息
     * @throws Exception 如果未找到对应的组织成员或数据库查询出错，抛出异常
     */
    @Override
    public V3xOrgMember getOrgMember(String templateCode, JSONObject mainData, FormBean formBean) throws Exception {
        // 获取表单中所有字段的列表
        List<FormFieldBean> allFieldBeans = formBean.getAllFieldBeans();
        String jbr_unFlowformCode = AppContext.getSystemProperty("oaFormCode.jbr_unFlowformCode");
        FormBean jbrFormBean = cap4FormManager.getFormByFormCode(jbr_unFlowformCode);
        // 获取经办人字段的名称
        String operator_fieldName = jbrFormBean.getFieldBeanByDisplay("经办人").getName();
        // 获取主表的表名
        String tableName = jbrFormBean.getMasterTableBean().getTableName();
        // 获取模板编号字段的名称
        String templateCode_fieldName = jbrFormBean.getFieldBeanByDisplay("模板编号").getName();
        // 使用StringBuilder来构建SQL查询语句
        StringBuilder stb = new StringBuilder();
        // 开始构建SQL查询语句，从指定表中选择经办人
        stb.append("select ").append(operator_fieldName).append(" from ").append(tableName);
        // 添加模板编码的查询条件
        stb.append(" where ").append(templateCode_fieldName).append(" ='").append(templateCode).append("'");
        // 使用StringBuilder来构建提示信息
        StringBuilder msgStb = new StringBuilder();
        // 开始构建提示信息
        msgStb.append("根据模版编码[").append(templateCode).append("]");
        // 遍历所有字段，寻找类型为select的字段
        for (FormFieldBean formFieldBean : allFieldBeans) {
            String fieldType = formFieldBean.getInputType();
            if ("select".equals(fieldType)) {
                String enumId = StrKit.str(formFieldBean.getEnumId());
                String oa_enumId = StrKit.str(AppContext.getSystemProperty("oa.enumId"));
                String enumItemId = "";
                // 获取区县字段的名称
                String county_fieldName = jbrFormBean.getFieldBeanByDisplay("区县").getName();
                // 如果枚举ID与系统属性中的枚举ID相等
                if (oa_enumId.equals(enumId)) {
                    String fieldDesc = formFieldBean.getDesc();
                    String key = "";

                    // 处理字段描述，获取实际的键值
                    if (fieldDesc.contains("_")) {
                        key = StrKit.str(fieldDesc.split("_")[1]);
                    } else {
                        key = fieldDesc;
                    }
                    // 获取表单数据中对应键的值，并转换为字符串
                    String enumItemCode = StrKit.str(mainData.get(key));
                    if (!"".equals(enumItemCode)) {
                        // 重新构建枚举项代码
                        String enumItemCode_new = "";
                        if (fieldDesc.contains("_")) {
                            enumItemCode_new = fieldDesc.split("_")[0] + "_" + enumItemCode;
                        } else {
                            enumItemCode_new = enumItemCode;
                        }
                        // 如果新的枚举项代码不为空，则获取对应的枚举项ID
                        if (!"".equals(enumItemCode_new)) {
                            CtpEnumItem ctpEnumItem = DataConversionKit.getEnumByCode(enumItemCode_new);
                            if (ctpEnumItem == null) {
                                throw new BusinessException(key + " [" + enumItemCode + "]编码值有误,未匹配到对应的枚举值!");
                            } else {
                                enumItemId = StrKit.str(ctpEnumItem.getId());
                            }
                        }
                        // 添加区县枚举编码到提示信息中
                        msgStb.append(",区县枚举编码[").append(enumItemCode).append("]");
                        // 添加区县字段的查询条件
                        stb.append(" and ").append(county_fieldName).append(" ='").append(enumItemId).append("'");
                    }
                }
            }
        }
        // 执行SQL查询，获取列表
        List<Map<String, Object>> list = capDataListSqlHelpManager.selectDataList(stb.toString(), null);
        // 如果查询结果为空，抛出异常
        if (list.isEmpty()) {
            msgStb.append("未匹配到对应系统账号,请联系管理员查看[经办人档案]!");
            throw new BusinessException(msgStb.toString());
        }
        // 获取查询结果中的第一个经办人ID
        String operatorId = StrKit.str(list.get(0).get(operator_fieldName));
        // 根据经办人ID获取组织成员信息
        V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(operatorId));
        // 返回组织成员信息
        return v3xOrgMember;
    }

    /**
     * 根据文件ID和URL获取文件列表
     *
     * @param fileId 文件ID
     * @param url    文件服务URL
     * @return 文件列表，每个文件信息包括名称和URL
     * @throws Exception 可能抛出的异常
     */
    private List<Map<String, Object>> getFile(String fileId, String url) throws Exception {
        List<Map<String, Object>> fileList = new ArrayList<Map<String, Object>>();
        try {
            String file_url = AppContext.getSystemProperty("oa.url");
            // 根据子引用ID获取附件记录列表
            List<Long> list = attachmentManager.getBySubReference(Long.parseLong(fileId));
            long memberId = fileManager.getV3XFile(list.get(0)).getCreateMember();
            // 获取文件创建者的登录名
            String loginName = orgManager.getMemberById(memberId).getLoginName();
            // 构建获取token的URL
            String tokenUrl = url + "/seeyon/rest/token";
            // 准备获取token所需的信息
            Map<String, Object> tokenMap = new HashMap<String, Object>();
            tokenMap.put("userName", userName);
            tokenMap.put("password", password);
            // 将登录名添加到token请求参数中
            tokenMap.put("loginName", loginName);
            // 发起请求获取token
            String token_result = HttpKit.post(tokenUrl, new HashMap<>(), JSON.toJSONString(tokenMap));
            log.info("token_result:" + token_result);
            // 解析token请求结果
            JSONObject token_obj = JSONObject.parseObject(token_result);
            String tokenId = StrKit.str(token_obj.get("id"));
            // 遍历附件记录列表，为每个文件生成访问信息
            for (Long fileUrl : list) {
                Map<String, Object> map = new HashMap<String, Object>();
                // 获取V3X文件信息
                V3XFile v3xFile = fileManager.getV3XFile(fileUrl);
                // 设置文件名
                map.put("name", v3xFile.getFilename());
                // 构建文件访问URL
                String attUrl = file_url + "/seeyon/rest/attachment/file/" + fileUrl + "?fileName=" + URLEncoder.encode(v3xFile.getFilename(), "UTF-8") + "&token=" + tokenId + "";
                // 将文件URL添加到文件信息中，并对URL进行编码处理
                map.put("url", attUrl);
                // 将文件信息添加到文件列表中
                fileList.add(map);
            }
            // 返回文件列表
            return fileList;
        } catch (Exception e) {
            // 记录获取文件列表过程中的异常
            log.error("获取文件列表异常", e);
            // 在发生异常时返回空的文件列表
            return fileList;
        }
    }

    private Object getData(String fieldType, Object fieldValue, String url) throws Exception{
        Object fieldValue_new = "";
        if ("imageselect".equals(fieldType) || "radio".equals(fieldType) || "select".equals(fieldType)) {
            fieldValue_new = enumManager.getCtpEnumItem(Long.parseLong(StrKit.str(fieldValue))).getShowvalue();
        } else if ("datetime".equals(fieldType)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            fieldValue_new = sdf.format((Date) fieldValue);
        } else if ("date".equals(fieldType)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            fieldValue_new = sdf.format((Date) fieldValue);
        } else if ("attachment".equals(fieldType) || "image".equals(fieldType)) {
            fieldValue_new = getFile(StrKit.str(fieldValue), url);
        } else if ("checkbox".equals(fieldType)) {
            if ("1".equals(StrKit.str(fieldValue))) {
                fieldValue_new = "是";
            } else {
                fieldValue_new = "否";
            }
        } else {
            fieldValue_new = StrKit.str(fieldValue);
        }
        return fieldValue_new;
    }


}
